<?php
namespace Home\Controller;
use Think\Controller;
use Home\Controller\BaseController;

class ShopstreetController extends BaseController
{
    //店铺街首页
    public function index(){
        switch(I('get.sorting')){
            case 1:
                $sorting = "store_sales desc";
                $style['sales'] = 'active first';
                break;
            case 2:
                $sorting = "store_credit desc";
                $style['credit'] = 'active first';
                break;
            default:
                $sorting = "store_collect desc";
                $style['default'] = 'active first';
        }
        
        $where['store_recommend'] = 1;
        
        $this->assign('style',$style);
        $store = M('Store');
        $count      = $store->where($where)->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,15);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show       = $Page->show();// 分页显示输出
        $list = $store->where($where)->order($sorting)->limit($Page->firstRow.','.$Page->listRows)->select();
        $where['goods_sale'] = 1;
        $where['goods_state'] = 1;
        foreach($list as $k=>$v){
            $list[$k]['praise'] = ($v['store_desccredit']+$v['store_servicecredit']+$v['store_deliverycredit'])/3;
            $where['store_id'] = $v['store_id'];
            $goods[$k] = M('Goods')->where($where)->limit(4)->order('goods_hits desc')->select();
        }
        $this->assign('goods',$goods);
        $this->assign('num',$count);
        $this->assign('list',$list);// 赋值数据集
        $this->assign('page',$show);// 赋值分页输出
        //
        //店家精选(广告位)
        $where2['goods_sale'] = 1;
        $where2['goods_state'] = 1;
        $tuijian = M('Goods')->where($where2)->limit(10)->order('goods_hits desc')->select();
        $this->assign('tuijian',$tuijian);

        $this->display();
    }
}

